package com.belf.web.controller.system;

import com.belf.common.config.BelfConfig;
import com.belf.common.core.domain.AjaxResult;
import com.belf.common.core.domain.entity.SysUser;
import com.belf.common.utils.SecurityUtils;
import com.belf.common.utils.StringUtils;
import com.belf.console.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 首页
 *
 * @author belf
 */
@RestController
@RequestMapping("/console")
public class SysIndexController
{
    /** 系统基础配置 */
    @Autowired
    private BelfConfig BelfConfig;
    @Autowired
    private IDataSourceInfoService dataSourceInfoService;

    @Autowired
    private IAppraiseTasksService appraiseTasksService;
    @Autowired
    private IDataCheckTaskService dataCheckTaskService;
    @Autowired
    private IDataTaskConfService dataTaskConfService;

    @Autowired
    private IDataTaskLogService dataTaskLogService;

    /**
     * 访问首页，提示语
     */
    @RequestMapping("/")
    public String index()
    {
        return StringUtils.format("欢迎使用{}后台管理框架，当前版本：v{}，请通过前端地址访问。", BelfConfig.getName(), BelfConfig.getVersion());
    }

    /**
     * 查询数据源信息列表
     */
    @PostMapping("/dataSourceCount")
    @ResponseBody
    public AjaxResult selectDataSourceInfoCount()
    {
        // 管理员拥有所有权限
        SysUser user = SecurityUtils.getLoginUser().getUser();
        return dataSourceInfoService.selectDataSourceInfoCount(user);
    }

    /**
     * 查询数据源信息列表
     */
    @PostMapping("/taskCount")
    @ResponseBody
    public AjaxResult selectTaskCount()
    {
        // 管理员拥有所有权限
        SysUser user = SecurityUtils.getLoginUser().getUser();
        HashMap<String, HashMap<String, Integer>> dataMap = new HashMap<>();
        dataMap.putAll(appraiseTasksService.selectParseCount(user));
        dataMap.putAll(dataCheckTaskService.selectParseCount(user));
        dataMap.putAll(dataTaskConfService.selectParseCount(user));
         return   AjaxResult.success(dataMap);
    }
}
